from Autotests.BaseTest import AirManagerTestCase
from Autotests.LocalMachine.Pages.AirManager.MainPage import WebMainPage


class Groups(AirManagerTestCase):
    def test_AddEditDeleteGroup(self):
        groupForAdd = 'newGroup'
        groupForDelete = 'newGroup_2'
        main = WebMainPage()

        if groupForAdd in main.getGroupList(): main.deleteGroup(groupForAdd)
        if groupForDelete in main.getGroupList(): main.deleteGroup(groupForDelete)

        count = main.getGroupCount()
        main.addGroup(groupForAdd)
        self.assertEqual(count + 1, main.getGroupCount(), 'Check group count after "Add group"')
        self.assertTrue(groupForAdd in main.getGroupList(), 'Check group %s is in group list' % groupForAdd)

        main.editGroup(groupForAdd, groupForDelete)
        self.assertEqual(count + 1, main.getGroupCount(), 'Check group count after "Edit group"')
        self.assertTrue(groupForAdd not in main.getGroupList(), 'Check group %s is not in group list' % groupForAdd)
        self.assertTrue(groupForDelete in main.getGroupList(), 'Check group %s is in group list' % groupForDelete)

        main.deleteGroup(groupForDelete)
        self.assertEqual(count, main.getGroupCount(), 'Check group count after "Delete group"')
        self.assertTrue(groupForDelete not in main.getGroupList(),
                        'Check group %s is not in group list' % groupForDelete)


import unittest
if __name__ == "__main__":
    unittest.main()